import time, osfrom django.shortcuts import renderfrom django.conf import settingsfrom .utils import get_categoriesfrom .models import ContentCategorydef generate_static_index_html():    print('%s: generate_static_index_html' % time.ctime())    # 获取商品频道和分类    categories = get_categories()    # 广告内容    contents = {}    content_categories = ContentCategory.objects.all()    for cat in content_categories:        contents[cat.key] = cat.content_set.filter(status=True).order_by('sequence')    # 渲染模板    context = {        'categories': categories,        'contents': contents    }    response = render(None, 'index.html', context)    html_text = response.content.decode()    file_path = os.path.join(settings.STATICFILES_DIRS[0], 'index.html')    with open(file_path, 'w', encoding='utf-8') as f:        f.write(html_text)